package org.jeecg.modules.haili.service.impl;

import com.alibaba.fastjson.JSONObject;
import org.jeecg.modules.haili.service.IUnderWritingService;
import org.jeecg.modules.haili.entity.request.Message;
import org.jeecg.modules.haili.entity.insurance.OriginInsOrder;
import org.jeecg.modules.haili.entity.response.MessageResponse;
import org.jeecg.modules.haili.utils.MessageBuilder;
import org.jeecg.modules.haili.utils.Messenger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 投保(核保、承保)实现接口
 */
@Service
public class UnderWritingServiceImpl implements IUnderWritingService {
    private Logger logger = LoggerFactory.getLogger(UnderWritingServiceImpl.class);

    @Autowired
    Messenger messenger;

    @Autowired
    MessageBuilder messageBuilder;

    @Override
    public MessageResponse underOrder(OriginInsOrder originInsOrder) {
        Message message = messageBuilder.convertOrignOrderToJsonMessage(originInsOrder);

        //发送报文
        String response = messenger.sendMessage(message);
        return JSONObject.parseObject(response, MessageResponse.class);
    }

    @Override
    public MessageResponse chengbaoOrder(OriginInsOrder order, MessageResponse underResponse) {
        Message message = messageBuilder.convertResToChengBaoJsonMessage(order,underResponse);
        //发送报文
        String response = messenger.sendMessage(message);
        return JSONObject.parseObject(response, MessageResponse.class);
    }
}
